#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

using vec = vector<int>;

int find(vec &f, int x)
{
	return f[x] == x ? x : f[x] = find(f, f[x]);
}

int merge(vec &f, int x, int y)
{
	int fx = find(f, x);
	int fy = find(f, y);
	if (fx == fy) {
		return 0;
	}
	f[fx] = fy;
	return 1;
}

int main()
{
	int n, m, p, x, y;
	cin >> n >> m;
	vec father(n + 1, 0);
	vec ene(n + 1, 0);

        iota(father.begin(), father.end(), 0);

	for (int i = 0; i < m; i++) {
		cin >> p >> x >> y;
		if (p == 0) {
			merge(father, x, y);
			continue;
		}
		if (ene[x] == 0) {
			ene[x] = y;
		}
		merge(father, ene[x], y);
                if(ene[y] == 0){
                        ene[y] = x;
                }
                merge(father, ene[y], x);
	}

        int ans = 0;
        for(int i = 1; i <= n; i++){
                if(father[i] == i){
                        ans++;
                }
        }
        cout<<ans<<endl;
	return 0;
}